﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace WLYT.Common
{
    public class SessionHelper
    {
        /// <summary>
        /// 获取Session值
        /// </summary>
        /// <param name="key">Session的Key值</param>
        /// <returns>Session的Value值</returns>
        public static object GetSession(string key)
        {
            return HttpContext.Current.Session[key];
        }

        /// <summary>
        /// 获取Session（泛型）
        /// </summary>
        /// <typeparam name="T">希望获得的类型</typeparam>
        /// <param name="key">Session的Key值</param>
        /// <returns>Session的Value值</returns>
        public static T GetSession<T>(string key)
        {
            return ((T)(HttpContext.Current.Session[key]));
        }


        /// <summary>
        /// 设置一个Session
        /// </summary>
        /// <param name="key">Session的Key值</param>
        /// <param name="value">Session的Value值</param>
        public static void SetSession(string key, object value)
        {
            HttpContext.Current.Session.Remove(key);
            HttpContext.Current.Session.Add(key, value);
        }
    }
}
